import { NodeSize } from '../config'

export default function rest(flow) {
  flow.register('Rest', ({ PolygonNode, PolygonNodeModel, h }) => {
    class Node extends PolygonNode {
      getIconShape() {
        return h(
          'svg',
          {
            width: NodeSize,
            height: NodeSize,
            viewBox: '0 0 1024 1024'
          },
          h(
            'path',
            {
              fill: '#EFF9FE',
              d: 'M398.969905 362.276571a467.21219 467.21219 0 0 1-78.726095-29.086476 284.574476 284.574476 0 0 0-78.799239 187.343238h128.146286c1.121524-55.05219 10.947048-108.568381 29.379048-158.256762zM457.386667 253.269333a285.086476 285.086476 0 0 0-121.977905 65.26781c22.893714 10.459429 46.713905 19.090286 71.216762 25.648762a451.413333 451.413333 0 0 1 50.761143-90.916572zM417.353143 693.345524a498.858667 498.858667 0 0 1 99.766857-11.751619v-141.507048h-128.024381a468.455619 468.455619 0 0 0 28.257524 153.258667zM389.12 520.557714h128v-141.409524a486.863238 486.863238 0 0 1-98.962286-12.141714 462.60419 462.60419 0 0 0-29.037714 153.551238zM369.566476 540.062476H241.444571a284.525714 284.525714 0 0 0 78.214096 186.684953 464.62781 464.62781 0 0 1 78.579809-28.647619c-17.993143-49.39581-27.623619-102.838857-28.672-158.037334zM334.57981 741.302857a285.257143 285.257143 0 0 0 121.222095 65.633524 441.027048 441.027048 0 0 1-50.078476-90.624 443.66019 443.66019 0 0 0-71.143619 24.990476zM425.886476 348.745143c29.720381 6.558476 60.269714 10.24 91.233524 10.873905v-114.736762a285.744762 285.744762 0 0 0-30.159238 2.633143 427.812571 427.812571 0 0 0-61.074286 101.229714zM485.327238 812.860952c10.435048 1.536 21.016381 2.511238 31.792762 2.876953v-114.639238c-31.329524 0.585143-62.244571 4.144762-92.233143 10.605714a416.426667 416.426667 0 0 0 60.440381 101.156571z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M667.696762 578.145524c25.819429 0 46.83581-20.992 46.835809-46.811429s-21.016381-46.83581-46.835809-46.835809c-22.089143 0-40.545524 15.433143-45.421714 36.059428h-85.625905v-141.092571h155.964952c4.169143 21.577143 23.161905 37.936762 45.933715 37.936762 25.819429 0 46.811429-21.016381 46.811428-46.83581s-20.992-46.811429-46.811428-46.811428a46.811429 46.811429 0 0 0-45.494858 36.181333h-156.403809v-115.541333h114.639238c7.582476 15.652571 23.478857 26.575238 42.008381 26.575238 25.819429 0 46.83581-21.016381 46.835809-46.83581s-21.016381-46.811429-46.835809-46.811428c-18.16381 0-33.743238 10.50819-41.520762 25.648762H526.872381c-180.49219 0-327.363048 146.846476-327.363048 327.363047 0 169.496381 129.511619 309.296762 294.765715 325.705143l42.349714-39.18019V540.062476h85.113905c4.144762 21.650286 23.137524 38.083048 45.958095 38.083048z m0-74.118095a27.306667 27.306667 0 0 1 0 54.588952 27.306667 27.306667 0 0 1 0-54.588952z m70.851048-160.768a27.306667 27.306667 0 1 1-0.073143 54.613333 27.306667 27.306667 0 0 1 0.073143-54.613333z m-45.251048-146.432a27.306667 27.306667 0 0 1 0 54.588952 27.306667 27.306667 0 0 1 0-54.588952z m-235.910095 56.441904a451.413333 451.413333 0 0 0-50.761143 90.916572 448.121905 448.121905 0 0 1-71.216762-25.648762 285.500952 285.500952 0 0 1 121.977905-65.26781z m-137.118477 79.920762c25.185524 12.01981 51.565714 21.674667 78.726096 29.086476-18.432 49.688381-28.281905 103.204571-29.379048 158.256762H241.444571a284.574476 284.574476 0 0 1 78.823619-187.343238z m-78.823619 206.872381h128.121905c1.024 55.198476 10.678857 108.617143 28.672 158.037334a462.506667 462.506667 0 0 0-78.579809 28.647619 284.647619 284.647619 0 0 1-78.214096-186.684953z m93.135239 201.240381a446.902857 446.902857 0 0 1 71.143619-24.990476 439.881143 439.881143 0 0 0 50.078476 90.624 285.110857 285.110857 0 0 1-121.222095-65.633524z m182.54019 74.435048a284.696381 284.696381 0 0 1-31.792762-2.876953 415.329524 415.329524 0 0 1-60.440381-101.156571 480.719238 480.719238 0 0 1 92.233143-10.605714v114.639238z m0-134.144c-33.889524 0.609524-67.364571 4.534857-99.766857 11.751619a468.48 468.48 0 0 1-28.257524-153.283048h128.024381v141.531429z m0-161.036191h-128a462.60419 462.60419 0 0 1 29.037714-153.551238c32.207238 7.363048 65.365333 11.483429 98.962286 12.141714v141.409524z m0-160.938666a467.992381 467.992381 0 0 1-91.233524-10.873905 427.812571 427.812571 0 0 1 61.074286-101.229714c9.898667-1.389714 19.943619-2.267429 30.159238-2.633143v114.736762z'
            }
          ),
          h(
            'path',
            {
              fill: '#EFF9FE',
              d: 'M738.54781 370.566095m-27.306667 0a27.306667 27.306667 0 1 0 54.613333 0 27.306667 27.306667 0 1 0-54.613333 0Z'
            }
          ),
          h(
            'path',
            {
              fill: '#EFF9FE',
              d: 'M693.296762 224.134095m-27.306667 0a27.306667 27.306667 0 1 0 54.613334 0 27.306667 27.306667 0 1 0-54.613334 0Z'
            }
          ),
          h(
            'path',
            {
              fill: '#EFF9FE',
              d: 'M667.696762 531.309714m-27.306667 0a27.306667 27.306667 0 1 0 54.613334 0 27.306667 27.306667 0 1 0-54.613334 0Z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M151.30819 119.856762V104.106667c0-18.236952-9.45981-29.330286-34.06019-29.330286H73.142857v114.102857h18.968381V149.357714h22.991238l27.233524 39.521524h22.137905L135.338667 146.578286c11.556571-4.559238 15.969524-14.06781 15.969523-26.721524z m-18.96838 0.170667c0 8.850286-2.974476 11.995429-15.60381 11.995428h-24.624762v-39.740952h24.624762c12.653714 0 15.60381 3.023238 15.60381 11.995428v15.750096zM246.101333 171.373714H195.754667v-32.182857h46.567619v-17.505524h-46.567619V92.281905h50.176v-17.505524H176.786286v114.102857h69.315047zM296.448 173.177905c-9.728 0-19.992381-1.609143-29.769143-4.632381l-2.584381-0.804572-3.218286 16.11581 1.877334 0.731428c9.679238 3.925333 22.649905 5.924571 33.353143 5.924572 31.329524 0 38.058667-11.873524 38.058666-32.280381 0-22.649905-2.462476-27.745524-32.353523-35.157333-11.190857-2.779429-15.701333-4.169143-17.798096-6.290286-0.853333-0.877714-1.389714-1.999238-1.682285-3.949714-0.316952-2.169905-0.316952-4.924952-0.316953-8.557715 0-10.825143 1.682286-13.775238 18.724572-13.775238 8.850286 0 18.968381 1.121524 27.501714 3.047619l2.706286 0.609524 1.609142-16.798476-1.999238-0.512A126.610286 126.610286 0 0 0 300.397714 73.142857c-28.086857 0-37.376 9.97181-37.376 30.646857 0 23.868952 4.022857 29.891048 31.427048 36.010667 11.556571 2.608762 16.335238 4.120381 18.578286 6.314667a6.680381 6.680381 0 0 1 1.80419 4.047238c0.365714 2.169905 0.341333 4.900571 0.341333 8.435809 0 10.776381-2.194286 14.57981-18.724571 14.57981zM375.856762 188.879238h18.968381V92.281905h32.621714v-17.505524h-84.23619v17.505524h32.646095z'
            }
          ),
          h(
            'path',
            {
              fill: '#FF9C04',
              d: 'M946.200381 735.378286l-9.167238-9.167238a99.718095 99.718095 0 0 0-137.97181-3.31581 0.658286 0.658286 0 0 1-0.195047-0.170667l-50.029715 50.054096a100.376381 100.376381 0 0 0-20.796952 106.76419l34.474667-34.474667a58.61181 58.61181 0 0 1 16.969143-44.665904l16.335238-16.359619v0.024381l30.817523-30.817524 0.195048 0.195047a58.514286 58.514286 0 0 1 80.896 2.023619l9.167238 9.167239a59.099429 59.099429 0 0 1 0 83.407238l-44.909714 44.909714c-16.920381 16.871619-43.324952 20.845714-64.804572 12.166095l-30.72 30.72a99.59619 99.59619 0 0 0 53.833143 15.823238c26.819048 0 52.028952-10.459429 70.972953-29.427809l44.909714-44.909715a100.449524 100.449524 0 0 0 0.024381-141.945904z'
            }
          ),
          h(
            'path',
            {
              fill: '#FF9C04',
              d: 'M804.376381 885.199238l7.826286-7.850667a100.522667 100.522667 0 0 0 22.064762-108.690285l-34.425905 34.450285a58.514286 58.514286 0 0 1-11.410286 38.229334l0.414476 0.414476-4.120381 4.120381c-0.633905 0.707048-1.097143 1.511619-1.80419 2.194286l-16.359619 16.359619-0.121905-0.292572-33.621333 33.621334-0.780191 0.024381c-22.77181 17.042286-57.027048 15.579429-77.409524-4.803048l-9.167238-9.167238a59.050667 59.050667 0 0 1 0.024381-83.382857l44.885334-44.934096a58.660571 58.660571 0 0 1 65.048381-12.385523l30.47619-30.476191a99.474286 99.474286 0 0 0-53.833143-15.847619c-26.819048 0-52.028952 10.459429-70.997333 29.42781l-44.885333 44.934095a100.522667 100.522667 0 0 0-0.024381 141.945905l9.167238 9.167238a99.718095 99.718095 0 0 0 137.971809 3.291428l0.219429 0.195048 40.764952-40.740572 0.097524 0.195048z'
            }
          )
        )
      }

      getLabelShape() {
        return h(
          'text',
          {
            fill: '#000000',
            fontSize: 12,
            x: NodeSize / 2,
            y: NodeSize + 20,
            textAnchor: 'middle',
            dominantBaseline: 'middle'
          },
          'Rest Client查询'
        )
      }

      getShape() {
        const { x, y, width, height } = this.getAttributes()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'rect',
              {
                rx: 5,
                ry: 5,
                width: NodeSize,
                height: NodeSize,
                fill: '#fff',
                stroke: '#3D6380',
                strokeWidth: 1
              }
            ),
            this.getIconShape(),
            this.getLabelShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor(data, graphModel) {
        super(data, graphModel)
        this.points = [
          [NodeSize / 2, 0],
          [NodeSize, NodeSize / 2],
          [NodeSize / 2, NodeSize],
          [0, NodeSize / 2]
        ]
      }
    }

    return {
      view: Node,
      model: Model
    }
  })
}
